--- title: "L2-034 口罩发放" created: 2025-11-28 tags: - 算法 --- # L2-034 口罩发放 ## 题目 [L2-034 口罩发放](https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=1336215880692482057&page=1) ![[image-d4ac769e.png]] ## 思路分析 ## 代码实现 ```cpp #include using namespace std; #define endl '\n' #define int long long using ll = long long; using ull = unsigned long long; using PII = pair; using Pll = pair; int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 }; const int inf = 0x3f3f3f3f; struct People { string name; string id; int bodyState; string time; int sx; bool operator<(const People& rhs) const { if(time!=rhs.time) return time>d>>p; map lastDay; // 记录每人上一次领取口罩的日期 map sickLogged; // 身体有症状的人员是否已记录 vector illPeople; // 身体不适人员名单 for (int day = 1; day <= d; ++day) { int t,s;//第?天 t个申请 s个名额 cin>>t>>s; vector applicants(t); for(int i=0; i> applicants[i].name >> applicants[i].id >> applicants[i].bodyState >> applicants[i].time; applicants[i].sx = i; // 输入顺序 } // 记录身体不适的合法人员 for(int i=0; i= s) break; // 检查间隔天数限制 if (lastDay.count(person.id) == 0 || lastDay[person.id] + p < day) { cout << person.name << " " << person.id << '\n'; lastDay[person.id] = day; ++given; } } } for (const auto& person : illPeople) { cout << person.name << " " << person.id << '\n'; } return 0; } ``` ## 同类题型 ## 视频讲解 --- ⬅️ [[L2-033 简单计算器|L2-033 简单计算器]] 🏠 [[00-天梯赛]] ➡️ [[L2-035 完全二叉树的层序遍历|L2-035 完全二叉树的层序遍历]]